package com.chinasoft.ssm.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybatisConfig {

    @Bean
    //   注入的是  SqlSessoinFactory
    public SqlSessionFactoryBean getSqlSessionFactory(@Autowired DataSource dataSource) {
        SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();
        // 注入 数据库连接池
        ssfb.setDataSource(dataSource);
        // 设置别名扫描 包路径
        ssfb.setTypeAliasesPackage("com.chinasoft.ssm.pojo");
        return ssfb;
    }

    @Bean
    // AccountMapper 会被注入容器
    public MapperScannerConfigurer getMapperScannerConfigurer() {
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.chinasoft.ssm.mapper");
        return msc;
    }


}
